//
//  SelectionValueCell.m
//  New_Runway
//
//  Created by mack on 2018/2/3.
//  Copyright © 2018年 NelsonJ. All rights reserved.
//

#import "SelectionValueCell.h"
#import "ZPSlider.h"
@interface SelectionValueCell ()
@property (nonatomic , copy) NSString *fromKm;
@property (nonatomic, copy) NSString *toKm;
@property (nonatomic, strong) NSArray *keyArray;
@property (nonatomic, strong)  ZPSlider *slider;

@end

@implementation SelectionValueCell


-(instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
         [self addAllViews];
    }
    return self;
    
}

-(void)addAllViews{
    
    [self PriceSlider];
}
-(void)setFirstIndex:(NSInteger)firstIndex{
    _firstIndex = firstIndex;
    self.slider.firstSelectedInedx =firstIndex;
    
}
-(void)setEndIndex:(NSInteger)endIndex{
    _endIndex = endIndex;
    self.slider.lastSelectedInedx = endIndex;
    
}
-(void)PriceSlider{
    _keyArray = @[@"0",@"1",@"3",@"6",@"10",@"不限"];
    ZPSlider *slider=[[ZPSlider alloc] initWithFrame:CGRectMake(30, 50, Screen_width - 60, 50) sliderTitles:_keyArray defaultFirstIndex:0 defaultLastIndex:5 sliderImage:[UIImage imageNamed:@"circle_s"]];
    [self addSubview:slider];
    self.slider = slider;
    slider.backgroundColor = [UIColor clearColor];
    //    slider.block=^(int index){
    //        NSLog(@"当前index==%d",index);
    //    };
    kSelfWeak;
    slider.block = ^(int firstIndexPath, int lastIndexPath) {
        if (firstIndexPath == 0 && lastIndexPath == 5) {
            weakSelf.toKm = @"不限";
            weakSelf.fromKm = @"";
           
        }
        if (firstIndexPath == 0 && lastIndexPath != 5) {
            
            weakSelf.toKm = weakSelf.keyArray[lastIndexPath];
            weakSelf.fromKm = @"";
        }
        if (firstIndexPath != 0 && lastIndexPath != 5) {
            weakSelf.toKm = weakSelf.keyArray[lastIndexPath];
            weakSelf.fromKm = weakSelf.keyArray[firstIndexPath];
            
        }
        if (firstIndexPath != 0 && lastIndexPath == 5) {
            weakSelf.toKm = @"不限";
            weakSelf.fromKm = weakSelf.keyArray[firstIndexPath];
            
        }
        weakSelf.KmBlock(weakSelf.fromKm, weakSelf.toKm, firstIndexPath, lastIndexPath);
        
    };
    
    UILabel *titleL = [[UILabel alloc] init];
    titleL.textColor = MAIN_FONT_COLOR();
    titleL.font = kFontSize(12);
    titleL.text = @"里程/单位（万公里）";
    [self addSubview:titleL];
    [titleL mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(weakSelf).mas_offset(14);
        make.top.equalTo(weakSelf).mas_offset(10);
    }];
    self.titleL = titleL;
    
    self.valueL = [[UILabel alloc] init];
    self.valueL.textColor = MAIN_NAV_COLOR();
    self.valueL.font = kFontSize(14);
    [self addSubview:self.valueL];
    [weakSelf.valueL mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(titleL.mas_right).mas_offset(3);
        make.centerY.equalTo(titleL);
    }];
    self.valueL.text = @"不限";
    
}
@end
